package com.ant.storage.controller;


import com.ant.storage.common.ResultCode;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.UserDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.service.IUserService;
import com.ant.storage.vo.UserVo;
import com.taobao.api.ApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-10-23
 */
@Api(tags = "人员信息")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @ApiOperation(value = "绑定信息")
    @PostMapping("/save")
    public ResultVo save(@RequestBody UserDto dto) throws ApiException {
        if (dto.getId() == null) {
            return ResultVo.success("操作成功", userService.saveUser(dto));
        } else {
            return ResultVo.success("操作成功", userService.updateUserById(dto));
        }

    }
    @ApiOperation(value = "获取员工列表")
    @GetMapping("/queryUserList")
    public ResultVo queryUserList(){
        List<UserVo> list = userService.userlist();
        return ResultVo.success("ok",list);
    }


    @ApiOperation(value = "查询员工详情")
    @GetMapping("/reviewUser")
    public ResultVo reviewUser(Integer id) throws ApiException {
        if (id == null) {
         throw new AntException(ResultCode.FAILURE.getResultCode(),"请输入id号");
        }
        userService.reviewUser(id);
        return ResultVo.success("操作成功");
    }

    @ApiOperation(value = "查询员工详情")
    @GetMapping("/queryUserOne")
    public ResultVo queryUserOne(String id) throws ApiException {
        if (id == null) {
            throw new AntException(ResultCode.FAILURE.getResultCode(),"请输入id号");
        }
        return userService.queryUserOne(id);
    }
}
